//
// Created by v on 19-7-11.
//

#include <unistd.h>

#include "CMCoapBroadcast.h"

#include "utils/cm_logprint.h"

CMLogPrint logPrint;

void test_coap_broad(const char *host, int port)
{
    CMCoapBroadcast broadcast(host, port);
    broadcast.setDebug(true);
    const char *senddata = "{\"result\":\"1\"}";
    broadcast.sendData(senddata, strlen(senddata), "qlink/success");
    int    count = 0;
    char * rdata = NULL;
    size_t rlen  = 0;
    while (count++ < 30)
    {
        int ret = broadcast.recvData(&rdata, &rlen, NULL);
        if (ret > 0)
        {
            cminfo("recv data [%d][%s]\n", rlen, rdata);
        }
        sleep(1);
    }
}

int main(int argc, char **args)
{
    const char *host = args[1];
    int         port = strtol(args[2], NULL, 10);

    CM_LOG_PRINT_INIT("broad");

    cminfo("use [%s:%d]\n", host, port);

    test_coap_broad(host, port);

    CM_LOG_PRINT_DEINIT();

    getchar();
    return 0;
}